<?php

namespace app\supplier\controller;

use app\api\controller\Henan;
use app\api\controller\Neimeng;
use app\api\controller\Qixin;
use app\erp\model\Attrdb;
use app\erp\model\Baojiadb;
use app\erp\model\Branddb;
use app\erp\model\Categorydb;
use app\erp\model\Goodsdb;
use app\erp\model\GoodsPriceLogdb;
use app\erp\model\Offerdb;
use app\erp\model\SalePricedb;
use app\erp\model\Sitedb;
use app\erp\model\UGoodsdb;
use app\jun\controller\Api;
use think\Db;

class Goods extends Base
{
    protected $db;
    protected $cols = array(
        array(
            'field' => 'goods_id',
            'width' => 40,
            'title' => 'ID',
            'type' => 'checkbox',
            'fixed' => 'left'
        ),
        array(
            'field' => 'goods_id',
            'width' => 100,
            'title' => 'ID',
            'hide' => 'true'
        ),
        array(
            'field' => 'category_name',
            'width' => 160,
            'title' => '分类',
            'sort' => true
        ),
        array(
            'field' => 'brand_name',
            'width' => 100,
            'title' => '品牌',
            'sort' => 'true'
        ),
        array(
            'field' => 'goods_picture',
            'width' => 80,
            'title' => '封面',
            'templet' => '#goods_picturesTpl'
        ),
        array(
            'field' => 'jun_id',
            'width' => 120,
            'title' => '军网编码',
        ),
        array(
            'field' => 'goods_sku',
            'width' => 180,
            'title' => '商品编号'
        ),
        array(
            'field' => 'goods_name',
            'width' => 300,
            'title' => '商品名称',
            'sort' => 'true'
        ),
        array(
            'field' => 'goods_model',
            'width' => 200,
            'title' => '商品型号'
        ),
        array(
            'field' => 'create_time',
            'width' => 120,
            'title' => '发布时间'
        ),
        array(
            'field' => 'market_price',
            'width' => 100,
            'title' => '市场价'
        ),
        array(
            'field' => 'sale_price',
            'width' => 100,
            'title' => '售价'
        ),
        array(
            'field' => 'api_price',
            'width' => 100,
            'title' => '报价'
        ),
        array(
            'field' => 'sale_state',
            'width' => 80,
            'title' => '销售',
            'templet' => '#sale_stateTpl'
        ),
        array(
            'field' => 'audit_state',
            'width' => 80,
            'title' => '泰龙吉审核',
            'templet' => '#audit_stateTpl'
        ),
        array(
            'field' => 'jun_state',
            'width' => 80,
            'title' => '军网推送审核',
            'templet' => '#jun_stateTpl'
        ),
        array(
            'field' => 'details',
            'width' => 160,
            'title' => '驳回内容'
        ),
        array(
            'fixed' => 'right',
            'width' => 60,
            'toolbar' => '#goods_tool',
            'title' => '操作'
        )
    );
    protected $mcols = array(
        array(
            'field' => 'goods_id',
            'width' => 40,
            'title' => 'ID',
            'type' => 'checkbox',
            'fixed' => 'left'
        ),
        array(
            'field' => 'goods_id',
            'width' => 100,
            'title' => 'ID',
            'hide' => 'true'
        ),
        array(
            'field' => 'category_name',
            'width' => 160,
            'title' => '分类',
            'sort' => true
        ),
        array(
            'field' => 'brand_name',
            'width' => 100,
            'title' => '品牌',
            'sort' => 'true'
        ),
        array(
            'field' => 'jun_id',
            'width' => 120,
            'title' => '军网编码',
        ),
        array(
            'field' => 'goods_sku',
            'width' => 180,
            'title' => '商品编号'
        ),
        array(
            'field' => 'goods_name',
            'width' => 300,
            'title' => '商品名称',
            'sort' => 'true'
        ),
        array(
            'field' => 'goods_model',
            'width' => 200,
            'title' => '商品型号'
        ),
        array(
            'field' => 'create_time',
            'width' => 120,
            'title' => '发布时间'
        ),
        array(
            'field' => 'market_price',
            'width' => 100,
            'title' => '市场价'
        ),
        array(
            'field' => 'sale_price',
            'width' => 100,
            'title' => '售价'
        ),
        array(
            'field' => 'api_price',
            'width' => 100,
            'title' => '报价'
        ),
        array(
            'field' => 'sale_state',
            'width' => 80,
            'title' => '销售',
            'templet' => '#sale_stateTpl'
        ),
        array(
            'field' => 'audit_state',
            'width' => 80,
            'title' => '泰龙吉审核',
            'templet' => '#audit_stateTpl'
        ),
        array(
            'field' => 'jun_state',
            'width' => 80,
            'title' => '军网审核',
            'templet' => '#jun_stateTpl'
        ),
        array(
            'field' => 'details',
            'width' => 160,
            'title' => '驳回内容'
        ),
        array(
            'fixed' => 'right',
            'width' => 90,
            'toolbar' => '#goods_tool2',
            'title' => '操作'
        )
    );
    protected $cols_jun = array(
        array(
            'field' => 'goods_id',
            'width' => 40,
            'title' => 'ID',
            'type' => 'checkbox',
            'fixed' => 'left'
        ),
        array(
            'field' => 'goods_id',
            'width' => 100,
            'title' => 'ID',
            'hide' => 'true'
        ),

        array(
            'fixed' => 'left',
            'width' => 80,
            'toolbar' => '#goods_jun_tool',
            'title' => '查看'
        ),
        array(
            'field' => 'category_name',
            'width' => 120,
            'title' => '分类',
            'templet' => '#category_nameTpl'
        ),
        array(
            'field' => 'jun_brand_name',
            'width' => 100,
            'title' => '品牌',
            'templet' => '#jun_brand_nameTpl'
        ),
        array(
            'field' => 'goods_picture',
            'width' => 80,
            'title' => '封面',
            'templet' => '#goods_pictureTpl'
        ),
        array(
            'field' => 'beizhu',
            'width' => 320,
            'title' => '运营备注'
        ),
        array(
            'field' => 'goods_sku',
            'width' => 110,
            'title' => '商品编号',
            'templet' => '#goods_skuTpl'
        ),
        array(
            'field' => 'jun_id',
            'width' => 120,
            'title' => '军采编号',
            'templet' => '#jun_idTpl'
        ),
        array(
            'field' => 'goods_name',
            'width' => 300,
            'title' => '商品名称',
            'templet' => '#goods_nameTpl'
        )
    ,
        array(
            'field' => 'create_time',
            'width' => 120,
            'title' => '发布时间',
            'templet' => '#create_timeTpl'
        ),
        array(
            'field' => 'sale_price',
            'width' => 100,
            'title' => '限价',
            'sort' => 'true',
            'templet' => '#sale_priceTpl'
        ),
        array(
            'field' => 'jun_zuidijia',
            'width' => 120,
            'title' => '最低价(参考)'
        ),
        array(
            'field' => 'sale_state',
            'width' => 80,
            'title' => '销售',
            'templet' => '#sale_stateTpl'
        ),
        array(
            'field' => 'view_stock',
            'width' => 80,
            'title' => '库存',
            'templet' => '#view_stockTpl'
        )
    );
    protected $cols_copy = array(
        array(
            'field' => 'goods_id',
            'width' => 40,
            'title' => 'ID',
            'type' => 'checkbox',
            'fixed' => 'left'
        ),
        array(
            'field' => 'category_name',
            'width' => 160,
            'title' => '分类',
            'sort' => true
        ),
        array(
            'field' => 'brand_name',
            'width' => 100,
            'title' => '品牌',
            'sort' => 'true'
        ),
        array(
            'field' => 'goods_picture',
            'width' => 80,
            'title' => '封面',
            'templet' => '#goods_pictureTpl'
        ),
        array(
            'field' => 'goods_sku',
            'width' => 120,
            'title' => '商品编号'
        ),
        array(
            'field' => 'goods_name',
            'width' => 300,
            'title' => '商品名称',
            'sort' => 'true'
        ),
        array(
            'field' => 'goods_model',
            'width' => 200,
            'title' => '商品型号'
        ),
        array(
            'field' => 'market_price',
            'width' => 100,
            'title' => '市场价'
        ),
        array(
            'field' => 'sale_price',
            'width' => 100,
            'title' => '售价'
        ),
        array(
            'field' => 'is_real',
            'width' => 100,
            'title' => '实物',
            'hide' => true,
            'templet' => '#is_realTpl'
        ),
        array(
            'field' => 'is_shopping',
            'width' => 100,
            'title' => '包邮',
            'hide' => true,
            'templet' => '#is_shoppingTpl'
        ),
        array(
            'field' => 'weight',
            'width' => 100,
            'hide' => true,
            'title' => '重量(克)'
        ),
        array(
            'field' => 'view_times',
            'width' => 100,
            'title' => '浏览量',
            'sort' => 'true'
        ),
        array(
            'field' => 'sale_num',
            'width' => 100,
            'title' => '销量',
            'sort' => 'true'
        ),
        array(
            'field' => 'is_install',
            'width' => 80,
            'title' => '安装',
            'templet' => '#is_installTpl'
        ),
        array(
            'field' => 'sale_state',
            'width' => 80,
            'title' => '销售',
            'templet' => '#sale_stateTpl'
        )
    );

    public $post = array();

    public function _initialize()
    {
        parent::_initialize();
        $request = request();
        $param = $request->param();
        $this->post = $param;
        $this->db = new Goodsdb ();
        $this->db->param = $this->post;
    }

    // 推送内蒙商品
    public function pushNeimengInfo($goods_sku)
    {
        $neimengapi = new Neimeng ();
        $this->db->param ['goods_sku'];
        $get_goods = $this->db->ajaxFind();
        $return = $neimengapi->sendGoods($get_goods);
        $this->db->ajaxSaveOne('api_option', json_encode($return));
        $this->db->ajaxsaveOne('out_goods_sku', $return ['goodsguid']);
        echo '商品推送成功';
    }

    // 推送齐心内蒙商品
    public function pushQixinInfo($goods_sku)
    {
        $qixinapi = new Qixin ();
        $this->db->param ['goods_sku'];
        $get_goods = $this->db->ajaxFind();
        $return = $qixinapi->sendGoods($get_goods);
        $this->db->ajaxSaveOne('api_option', json_encode($return));
        $this->db->ajaxsaveOne('out_goods_sku', $return ['goodsguid']);
        echo '商品推送成功';
    }

    // 推送河南商品价格
    public function pushHenanPrice($goods_sku)
    {
        $henanapi = new Henan ();
        $this->db->param ['goods_sku'];
        $get_goods = $this->db->ajaxFind();
        $henanapi->sendGoodsPrice($get_goods);
        echo '报价完成<br />下面是测试信息，以后屏蔽，调试使用：<br />';
        echo '<a target="_blank" href="' . url('pushHenanOther', array(
                'goods_sku' => $goods_sku,
                'mothed' => 'getGoodsInfo'
            )) . '">商品信息</a><br />';
        echo '<a target="_blank" href="' . url('pushHenanOther', array(
                'goods_sku' => $goods_sku,
                'mothed' => 'getGoodsPrice'
            )) . '">单个商品报价</a><br />';
        echo '<a target="_blank" href="' . url('pushHenanOther', array(
                'goods_sku' => $goods_sku,
                'mothed' => 'channelPrice'
            )) . '">取消报价</a><br />';
    }

    // 推送河南其他信息
    public function pushHenanOther($goods_sku, $mothed)
    {
        $henanapi = new Henan ();
        $this->db->param ['goods_sku'];
        $get_goods = $this->db->ajaxFind();
        switch ($mothed) {
            case 'getGoodsInfo' :
                $henanapi->getGoodsInfo($get_goods);
                echo '<br />商品信息获取完成<br />';
                break;
            case 'getGoodsPrice' :
                $henanapi->getGoodsPrice($get_goods);
                echo '<br />商品报价获取完成<br />';
                break;
            case 'channelPrice' :
                $henanapi->channelPrice($get_goods);
                echo '<br />撤销商品报价完成<br />';
                break;
        }
    }

    public function copy($select_site_id = '')
    {
        $categorydb = new Categorydb ();
        $category_all_sign = $categorydb->ajaxAllSign($select_site_id, 3);
        $category_sign_arr = array();
        foreach ($category_all_sign as $key => $val) {
            array_push($category_sign_arr, $val ['category_sign']);
        }
        $this->assign('category_sign_arr', implode(',', $category_sign_arr));
        $this->assign('select_site_id', $select_site_id);
        $this->assign('cols', json_encode($this->cols_copy));
        return $this->fetch();
    }

    public function collect($select_site_id = '')
    {
        $categorydb = new Categorydb ();
        $category_all_sign = $categorydb->ajaxAllSign($select_site_id, 3);
        $category_sign_arr = array();
        foreach ($category_all_sign as $key => $val) {
            array_push($category_sign_arr, $val ['category_sign']);
        }
        $this->assign('category_sign_arr', implode(',', $category_sign_arr));
        $this->assign('cols', json_encode($this->cols_copy));
        $this->assign('select_site_id', $select_site_id);
        return $this->fetch();
    }

    public function saveCopy()
    {
        if (!isset ($this->post ['goods_sku']) || count($this->post ['goods_sku']) == 0) {
            $this->layuiReturn('请选择要同步的商品');
        }
        if (SITE_ID == null && $this->post ['select_site_id'] == '') {
            $this->layuiReturn('请选择要同步的分站');
        }
        set_time_limit(800);
        Db::startTrans();
        $goodsdb = new Goodsdb ();
        $goodsdb->param ['site_id'] = 0;
        $goodsdb->param ['select_site_id'] = $this->post ['select_site_id'];
        $goodsdb->param ['sale_state'] = 1;
        $goodsdb->param ['is_copy'] = 1;
        $goodsdb->param ['audit_state'] = 1;
        $goodsdb->param ['goods_sku'] = $this->post ['goods_sku'];
        $goodsdb->copy();
        Db::commit();
        $this->layuiReturn('数据同步成功', '', '数据同步成功', 1);
    }

    public function saveCollect()
    {
        if (!isset ($this->post ['goods_sku']) || count($this->post ['goods_sku']) == 0) {
            $this->layuiReturn('请选择要采集的商品');
        }
        if (SITE_ID == null && $this->post ['select_site_id'] == '') {
            $this->layuiReturn('请选择要采集的分站');
        }
        set_time_limit(800);
        Db::startTrans();
        $goodsdb = new Goodsdb ();
        $goodsdb->param ['site_id'] = $this->post ['select_site_id'];
        $goodsdb->param ['select_site_id'] = 0;
        $goodsdb->param ['goods_sku'] = $this->post ['goods_sku'];
        $goodsdb->collect();
        Db::commit();
        $this->layuiReturn('数据采集成功', '', '数据采集成功', 1);
    }

    public function index()
    {
        $this->assign('cols', json_encode($this->cols));
        return $this->fetch();
    }

    public function detail($goods_sku)
    {
        $this->db->param ['goods_sku'] = $goods_sku;
        $data = $this->db->ajaxFind();
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function mindex()
    {
        $this->assign('cols', json_encode($this->mcols));
        return $this->fetch();
    }

    public function jun()
    {
        $this->assign('cols', json_encode($this->cols_jun));
        // 获取分站信息
        $sitedb = new Sitedb ();
        $get_site = $sitedb->ajaxFind(SITE_ID);
        $this->assign('get_site', $get_site);
        $this->assign('site_id', SITE_ID);
        // 获取分站列表
        $sitedb->param ['_o'] = 'site_id';
        $sitedb->param ['_b'] = 'asc';
        $sitedb->param ['page'] = 1;
        $sitedb->param ['limit'] = 1000;
        $get_site_list = $sitedb->ajaxSelect();
        $this->assign('site_list', $get_site_list ['data']);
        return $this->fetch();
    }

    public function tplForm()
    {
        // 获取分站信息
        $sitedb = new Sitedb ();
        $get_site = $sitedb->ajaxFind(SITE_ID);
        $this->assign('get_site', $get_site);
        $goods_sign = 0;
        $data = array();
        $data = $this->db->ajaxFind();
        $this->assign('data', json_encode($data));
        $goods_sign = $data ['goods_sku'];
        $this->assign('goods_sign', $goods_sign);
        $goods_id = isset ($data ['goods_id']) ? $data ['goods_id'] : '';
        $this->assign('goods_id', $goods_id);
        if (SITE_ID == 10) {
            // 河南的单独处理
            return $this->fetch('goods/tpl_form_henan');
            exit ();
        }
        return $this->fetch();
    }

    public function tplFormJun()
    {
        // 获取分站信息
        $sitedb = new Sitedb ();
        $get_site = $sitedb->ajaxFind(SITE_ID);
        $this->assign('get_site', $get_site);
        $goods_sign = 0;
        $data = array();
        $this->db->param ['pre_info'] = 'jun';
        $data = $this->db->ajaxFind();
        $this->assign('data', json_encode($data));
        $this->assign('goods_data', $data);
        $goods_sign = $data ['goods_sku'];
        $this->assign('goods_sign', $goods_sign);
        $goods_id = isset ($data ['goods_id']) ? $data ['goods_id'] : '';
        $this->assign('goods_id', $goods_id);
        return $this->fetch();
    }

    public function ajaxList($pre_info = '')
    {
        $this->db->param ['no_more_price'] = 'yes';
        $this->db->param ['pre_info'] = $pre_info;
        $this->db->param['lastbaojia'] = 'yes';
        $return = $this->db->ajaxSelect();
        $this->layuiReturn($return ['data'], $return ['count']);
    }

    public function ajaxMyList()
    {
        $this->db->param ['no_more_price'] = 'yes';
        $this->db->param ['pre_info'] = 'utec';
        $this->db->param ['admin_id'] = MEMBER_ID;
        $return = $this->db->ajaxSelect();
        $this->layuiReturn($return ['data'], $return ['count']);
    }

    public function ajaxCopyList()
    {
        $this->db->param ['site_id'] = 0;
        $this->db->param ['no_more_price'] = 'yes';
        $return = $this->db->ajaxSelect();
        $this->layuiReturn($return ['data'], $return ['count']);
    }

    public function ajaxCollectList()
    {
        if (isset ($this->db->param ['master_no'])) {
            $temp = explode(',', $this->db->param ['category_sign3']);
            if (count($temp) > 1) {
                $this->layuiReturn('请选择到三级分类', 0, '请选择到三级分类', -1);
            }
        }
        $this->db->param ['no_more_price'] = 'yes';
        $return = $this->db->ajaxSelect();
        $this->layuiReturn($return ['data'], $return ['count']);
    }

    public function saveData()
    {
        if ($this->post ['callet_juncai'] == 1) {
            $return = $this->db->ajaxSaveJuncai();
        } else {
            $return = $this->db->ajaxSave();
        }
        if ($return != 'success') {
            $this->layuiReturn($return, 0, $return, -1);
        } else {
            $this->layuiReturn($this->db->last_goods_sku);
        }
    }

    public function saveDataHenan()
    {
        $return = $this->db->ajaxUpdateHenan();
        if ($return != 'success') {
            $this->layuiReturn($this->db->last_goods_sku, 0, $return, -1);
        } else {
            $this->layuiReturn($this->db->last_goods_sku, 1, 'success', 1);
        }
    }

    /**
     *
     * @todo 软删除
     */
    public function ajaxDelete()
    {
        $this->db->param = $this->post;
        $this->db->ajaxDelete();
        $this->layuiReturn('删除成功', 0);
    }

    public function ajaxDown()
    {
        $where ['goods_id'] = array(
            'IN',
            $this->post ['goods_id']
        );
        $data ['sale_state'] = 2;
        $this->db->aloneSave($data, $where);
        $this->layuiReturn('保存成功');
    }


    public function ajaxUp()
    {
        $where ['goods_id'] = array(
            'IN',
            $this->post ['goods_id']
        );
        $data ['sale_state'] = 1;
        $this->db->aloneSave($data, $where);
        $this->layuiReturn('保存成功');
    }

    public function upload()
    {
        set_time_limit(3600);
        ini_set('memory_limit', '256M');
        $files = request()->file();
        vendor("PHPExcel.PHPExcel");
        $phpExcel = new \PHPExcel ();
        // 上传文件
        foreach ($files as $file) {
            $info = $file->validate([
                'site' => 1024 * 10 * 1024 * 1024,
                'ext' => 'xls,xlsx'
            ])->move('./uploads/');
            if ($info) {
                $fileName = './uploads/' . $info->getSaveName();
                $objReader = \PHPExcel_IOFactory::createReader('Excel5');
                $objReader->setReadDataOnly(true);
                $objPHPExcel = $objReader->load($fileName, $encode = 'utf-8');
                $sheet = $objPHPExcel->getSheet();
                $get_row_num = $sheet->getHighestRow(); // 总行数
                $get_col_num = $sheet->getHighestColumn(); // 总列
                $phpexcel_shared_date = new \PHPExcel_Shared_Date ();
                $data = array();
                $text = '';
                $categorydb = new Categorydb ();
                $branddb = new Branddb ();
                $attrdb = new Attrdb ();
                for ($i = 2; $i <= $get_row_num; $i++) {
                    unset ($temp);
                    $temp ['flag_i'] = $i;
                    $the_sheet = $objPHPExcel->getActiveSheet();
                    $temp ['category_name'] = $this->getSheetValue($the_sheet, "A" . $i);
                    $temp ['brand_name'] = $this->getSheetValue($the_sheet, "B" . $i);
                    $temp ['goods_name'] = $this->getSheetValue($the_sheet, "C" . $i);
                    $temp ['goods_son_name'] = $this->getSheetValue($the_sheet, "D" . $i);
                    $temp ['goods_model'] = $this->getSheetValue($the_sheet, "E" . $i);
                    $goods_sku = $this->getSheetValue($the_sheet, "F" . $i);
                    $temp ['goods_sku'] = $goods_sku ? $goods_sku : 'UTEC' . base_convert(uniqid(), 16, 10);
                    $temp ['weight'] = 0;
                    $temp ['goods_unit'] = $this->getSheetValue($the_sheet, "G" . $i);
                    $temp ['goods_keywords'] = $this->getSheetValue($the_sheet, "H" . $i);
                    $temp ['goods_intro'] = $this->getSheetValue($the_sheet, "I" . $i);
                    $temp ['goods_pictures'] = str_replace(';', ',', $this->getSheetValue($the_sheet, "J" . $i));
                    $temp ['sale_attr_price_name'] [0] = '商品价格';
                    $temp ['market_price'] [0] = $this->getSheetValue($the_sheet, "K" . $i);
                    $temp ['sale_price'] [0] = $this->getSheetValue($the_sheet, "L" . $i);
                    $api_price = $this->getSheetValue($the_sheet, "M" . $i);
                    $temp ['api_price'] [0] = $api_price ? $api_price : $temp ['sale_price'] [0];
                    $score = $this->getSheetValue($the_sheet, "N" . $i);
                    $temp ['give_score'] [0] = $score ? $score : 0;
                    $stock = $this->getSheetValue($the_sheet, "O" . $i);
                    $temp ['view_stock'] [0] = $stock ? $stock : 5;
                    $temp ['goods_attr'] = $this->getSheetValue($the_sheet, "P" . $i);
                    $temp ['goods_content'] = $this->getSheetValue($the_sheet, "Q" . $i);
                    $is_install = $this->getSheetValue($the_sheet, "R" . $i);
                    $temp ['is_install'] = $is_install == '是' ? 1 : 2;
                    $sale_state = $this->getSheetValue($the_sheet, "S" . $i);
                    $temp ['sale_state'] = $sale_state == '是' ? 1 : 2;
                    $is_copy = $this->getSheetValue($the_sheet, 'T' . $i);
                    $temp ['is_copy'] = $is_copy == '是' ? 1 : 2;
                    // 验证必填
                    if ($temp ['category_name'] == '' || $temp ['brand_name'] == '' || $temp ['goods_name'] == '' || $temp ['goods_model'] == '' || $temp ['goods_unit'] == '' || $temp ['market_price'] == '' || $temp ['sale_price'] == '') {
                        $this->layuiReturn('导入失败', 0, '红色的不能为空，请检查excel第' . $i . '行', 0);
                    }
                    // 验证重复
                    foreach ($data as $k => $v) {
                        if ($v ['goods_name'] == $temp ['goods_name']) {
                            $this->layuiReturn('导入失败', 0, '商品名称重复，请检查excel第' . $i . '行', 0);
                        }
                        if ($temp ['goods_sku'] != '' && $v ['goods_sku'] == $temp ['goods_sku']) {
                            $this->layuiReturn('导入失败', 0, '商品编号重复，请检查excel第' . $i . '行', 0);
                        }
                        if ($v ['goods_model'] == $temp ['goods_model']) {
                            $this->layuiReturn('导入失败', 0, '商品型号重复，请检查excel第' . $i . '行', 0);
                        }
                    }
                    // 验证分类是否存在
                    $categorydb->param ['category_sign'] = $temp ['category_name'];
                    $categorydb->param ['level'] = 3;
                    $chk_category = $categorydb->ajaxTreeFind($temp ['category_name']);
                    if (!$chk_category) {
                        $this->layuiReturn('导入失败', 0, '商品分类不存在，请检查excel第' . $i . '行', 0);
                    } else {
                        $temp ['category_sign1'] = $chk_category ['category_sign1'];
                        $temp ['category_sign2'] = $chk_category ['category_sign2'];
                        $temp ['category_sign3'] = $chk_category ['category_sign3'];
                    }
                    // 验证品牌是否存在
                    $chk_brand = $branddb->chkFind($temp ['brand_name']);
                    if (!$chk_brand) {
                        $this->layuiReturn('导入失败', 0, '商品品牌不存在，请检查excel第' . $i . '行', 0);
                    } else {
                        $temp ['brand_sign'] = $chk_brand ['brand_sign'];
                    }
                    // 验证属性是否存在
                    if ($temp ['goods_attr']) {
                        $get_attr_arr = explode(';', $temp ['goods_attr']);
                        foreach ($get_attr_arr as $k1 => $v1) {
                            $t1 = explode(':', $v1);
                            if (count($t1) != 2) {
                                $this->layuiReturn('导入失败', 0, '商品属性格式不正确，请检查excel第' . $i . '行', 0);
                            }
                            $attrdb->param ['category_sign'] = $temp ['category_sign3'];
                            $attrdb->param ['attr_name'] = $t1 [0];
                            $chk_attr = $attrdb->ajaxChkFind();
                            if (!$chk_attr) {
                                $this->layuiReturn('导入失败', 0, '商品属性（' . $t1 [0] . '）不存在，请检查excel第' . $i . '行', 0);
                            } else {
                                $temp [$chk_attr ['attr_sign']] = $t1 [1];
                            }
                        }
                    }
                    array_push($data, $temp);
                }
                $this->db->param = $data;
                $return = $this->db->ajaxSaveAll();
                if ($return == 'success') {
                    $this->layuiReturn('导入成功', 0, '导入成功', 1);
                } else {
                    $this->layuiReturn('导入失败', 0, $return, 0);
                }
            } else {
                $this->layuiReturn($file->getError(), 0, $file->getError(), 0);
            }
        }
    }

    public function transfer()
    {
        if (!isset ($this->post ['category_sign1']) || !isset ($this->post ['category_sign2']) || !isset ($this->post ['category_sign3']) || !isset ($this->post ['goods_arr'])) {
            $this->layuiReturn('参数错误', 0, '参数错误', 0);
        }
        $category_sign1 = $this->post ['category_sign1'];
        $category_sign2 = $this->post ['category_sign2'];
        $category_sign3 = $this->post ['category_sign3'];
        $goods_ids = $this->post ['goods_arr'];
        if ($category_sign1 == '' || $category_sign2 == '' || $category_sign3 == '' || $goods_ids == '') {
            $this->layuiReturn('参数错误', 0, '参数错误', 0);
        }
        $this->db->ajaxTransfer($category_sign1, $category_sign2, $category_sign3, $goods_ids);
        $this->layuiReturn('数据转移成功', 1, '数据转移成功', 1);
    }

    public function siteData()
    {
        if (!isset ($this->post ['goods_sku'])) {
            exit ('参数错误');
        }
        $this->db->param ['site_id'] = -1;
        $this->db->param ['goods_sku'] = $this->post ['goods_sku'];
        $this->db->param ['page'] = 1;
        $this->db->param ['limit'] = 50;
        $this->db->param ['_o'] = 'site_id';
        $this->db->param ['_b'] = 'desc';
        $data = $this->db->ajaxList();
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function saveSitePriceInfo()
    {
        if (!isset ($this->post ['sale_price_sign']) || !isset ($this->post ['value']) || !isset ($this->post ['field']) || !isset ($this->post ['goods_sku'])) {
            $this->layuiReturn('参数错误', 0, '参数错误', 0);
        }
        $this->db->param ['goods_sku'] = $this->post ['goods_sku'];
        $this->db->param ['site_id'] = $this->post ['site_id'];
        if ($this->post ['field'] != 'sale_state') {
            $get_goods_info = $this->db->ajaxFind();
            $salePricedb = new SalePricedb ();
            $salePricedb->param ['site_id'] = $this->post ['site_id'];
            $salePricedb->param ['sale_price_sign'] = $this->post ['sale_price_sign'];
            $salePricedb->param ['goods_sku'] = $this->post ['goods_sku'];
            $salePricedb->param ['field'] = $this->post ['field'];
            $salePricedb->param ['value'] = $this->post ['value'];
            $salePricedb->param ['category_sign3'] = $get_goods_info ['category_sign3'];
            $chk_return = $salePricedb->ajaxSaveFieldValue();
            $return = $salePricedb->ajaxFind();
            $this->db->writePriceRecord($this->post ['goods_sku']);
            $this->layuiReturn($return, 1, '数据保存成功', 1);
        } else {
            $this->db->ajaxSaveOne($this->post ['field'], $this->post ['value']);
            $this->layuiReturn('数据保存成功', 1, '数据保存成功', 1);
        }
    }

    public function chkModel()
    {
        if (!isset ($this->post ['value']) || !isset ($this->post ['goods_sign'])) {
            $this->layuiReturn('参数错误', 0, '参数错误', 0);
        }
        $this->db->param ['goods_model'] = $this->post ['value'];
        $this->db->param ['model_exact'] = 'yes';
        $get_goods_info = $this->db->chkGoodsModel();
        if (count($get_goods_info) > 0) {
            if ($get_goods_info ['goods_sku'] == $this->post ['goods_sign']) {
                $this->layuiReturn('', 0, '当前商品型号正常，可以修改数据', 2);
            } else {
                $this->layuiReturn($get_goods_info, 1, '商品型号已存在（商品编号：' . $get_goods_info ['goods_sku'] . '）', 1);
            }
        } else {
            $this->layuiReturn('', 0, '商品型号没有被录入', 0);
        }
    }
    /**
     * Title("导入报价单")
     */
    public function implodeJunXml()
    {
        set_time_limit(3600);
        ini_set('memory_limit', '256M');
        $files = request()->file();
        vendor("PHPExcel.PHPExcel");
        $phpExcel = new \PHPExcel ();
        // 上传文件
        foreach ($files as $file) {
            $info = $file->validate([
                'site' => 1024 * 10 * 1024 * 1024,
                'ext' => 'xls,xlsx'
            ])->move('./uploads/');
            if ($info) {
                $fileName = './uploads/' . $info->getSaveName();
                $objReader = \PHPExcel_IOFactory::createReader('Excel5');
                $objReader->setReadDataOnly(true);
                $objPHPExcel = $objReader->load($fileName, $encode = 'utf-8');
                $sheet = $objPHPExcel->getSheet();
                $get_row_num = $sheet->getHighestRow(); // 总行数
                $get_col_num = $sheet->getHighestColumn(); // 总列
                $phpexcel_shared_date = new \PHPExcel_Shared_Date ();
                $data = array();
                $text = '';
                $the_sheet = $objPHPExcel->getActiveSheet();
                $goodsDb = new Goodsdb();

                for ($i = 2; $i <= $get_row_num; $i++) {
                    unset ($temp);
                    $get_goods = $goodsDb->with(['salePrice'])
                        ->where('jun_id', $this->getSheetValue($the_sheet, "A" . $i))
                        ->whereNotLike('goods_sku', 'SKU%')
                        ->find();
                    if ($get_goods) {
                        $get_goods->append(['chk_brand_cert']);
                        $temp ['goods_id'] = $get_goods['goods_id'];
                        $temp['goods_name'] = $get_goods['goods_name'];
                        $temp ['goods_sku'] = $get_goods['goods_sku'];
                        $temp['sale_price'] = $get_goods['salePrice'][0]['sale_price'];
                        $temp['api_price'] = $this->getSheetValue($the_sheet, "B" . $i);
                        $temp['is_lock'] = $get_goods['is_lock'];
                        $temp ['sale_state'] = 1;
                        $temp ['audit_state'] = 1;
                        $temp ['view_stock'] = 4;
                        $temp['goods_type'] = '重点库';
                        $temp['chengbenjia'] = $this->getSheetValue($the_sheet, "C" . $i);
                        $temp['beizhu'] = $this->getSheetValue($the_sheet, "D" . $i) ?? '';
                        $temp['zhouqi'] = $this->getSheetValue($the_sheet, "E" . $i);
                        $temp['zhenshi'] = $this->getSheetValue($the_sheet, "F" . $i);// 真实库存
                        $temp['chk_brand_cert'] = $get_goods['chk_brand_cert'];
                        //$temp['zhenshi'] = 0;// 真实库存
                        $diqu = $this->getSheetValue($the_sheet, "G" . $i);
                        $diqu_id = '0';
                        if ($diqu == '非偏远地区') {
                            $diqu_id = '1';
                        }
                        if ($diqu == '偏远地区') {
                            $diqu_id = '2';
                        }
                        if ($get_goods['check_area'] == 0) {
                            $diqu_id = 0;
                        }
                        $temp['diqu'] = $diqu_id;// 地区
                        if ($diqu_id == 0) {
                            $temp['shengfen'] = null;// 省份
                        } else {
                            $temp['shengfen'] = $this->getSheetValue($the_sheet, "H" . $i);// 省份
                        }
                        $temp['zuidijia'] = $get_goods['salePrice'][0]['zuidijia'];
                        $temp['jun_id'] = $get_goods['jun_id'];
                        $temp ['check_area'] = $get_goods['check_area'];
                        $baojiadb = new Baojiadb();
                        $get_baojia = $baojiadb->where('goods_id', $get_goods['goods_id'])->order('baojia_id', 'desc')->value('create_time');
                        $temp ['lastbaojia'] = $get_baojia ? date('Y-m-d H:i', $get_baojia) : '';
                        // 校验今日是否报价
                        $chk_log = Db::name('goods_price_log')
                            //->fetchSql(true)
                            ->where('goods_sku', $get_goods['goods_sku'])
                            ->whereIn('types', ['供应商报价', '军采统一报价', '产品详情报价', '同步军网报价', '报价审核', '自动推送下架'])
                            ->whereTime('date', 'today')
                            ->whereLike('params','%"结果":"入库成功"%')
                            ->group('goods_sku')
                            ->count();
                        if ($chk_log > 0) {
                            $temp['is_lock'] = 3;
                        }
                        // 校验结束

                        array_push($data, $temp);
                    }
                }
                if (count($data) > 0) {
                    $this->layuiReturn($data, 0, '导入成功', 1);
                } else {
                    $this->layuiReturn('导入失败', 0, '没有数据', 0);
                }
            } else {
                $this->layuiReturn($file->getError(), 0, $file->getError(), 0);
            }
        }
    }

    public function saveBaojia()
    {
        $baojiadb = new Baojiadb();
        $baojiadb->param = $this->post;
        $baojiadb->param['apply_member_id'] = MEMBER_ID;
        $baojiadb->param['audit_state'] = 2;
        // 15%直接审核通过
        if (abs($this->post['lilv']) <= 0.15) {
            $baojiadb->param['audit_state'] = 1;
            $baojiadb->param['audit_member_id'] = MEMBER_ID;
            $baojiadb->param['audit_time'] = time();
            //   $baojiadb->param['beizhu'] = $baojiadb->param['beizhu'] . '__低于15%自动审核';
        }
        $baojiadb->save($baojiadb->param);
        // 推送军采
        $junapi = new Api();
        if ($this->post['goods_type'] == '重点库') {
            $post_jun['priceList'] = array();
            $price_list_arr['sku'] = $this->post['goods_sku'];
            $price_list_arr['stock'] = $this->post['kucun'];
            $price_list_arr['price'] = $this->post['baojia'];
            array_push($post_jun['priceList'], $price_list_arr);
            $junapi->ajaxCountPrice($post_jun);
        } else {
            $data = array();
            $temp ['sku'] = $this->post['goods_sku'];
            $temp ['updateType'] = 6;
            array_push($data, $temp);
            $junapi->ajaxproductupdateinfo($data);
        }
        // 同步分系统
        $uGoodsdb = new UGoodsdb();
        $uGoodsdb->chkGoods($this->post['goods_id']);

        $this->layuiReturn('保存成功');
    }

    /**
     * Title("保存报价申请")
     */
    public function saveCgGood()
    {
        if (isset ($this->post ['goods_id_arr'])) {
            $baojiadb = new Baojiadb();
            // 验证报价只能低于上次报价的1%
            /*$deff_rate = 0.01;
            foreach ($this->post ['goods_id_arr'] as $key => $val) {
                $get_last_baojia = $baojiadb->where('goods_id', $val)->value('baojia');
                if ($get_last_baojia) {
                    if ($this->post ['api_price_arr'] [$key] > $get_last_baojia * (1 - $deff_rate)) {
                        $this->layuiReturn($this->post['goods_sku_arr'][$key] . '降价幅度不能低于上次报价的' . ($deff_rate * 100) . '%',0,'error',2);
                    }
                }
            }*/
            // 验证结束
            $param = array();
            $goods_price_arr = array();
            $get_supplier = Db::name('member')->where('member_id', MEMBER_ID)->value('username');
            $audit_flag = 2;
            $goodsdb = new Goodsdb();
            $saledb = new SalePricedb();
            foreach ($this->post ['goods_id_arr'] as $key => $val) {
                $view_stock_arr = 4;
                // halt($val);
                $get_goods = $goodsdb->find($val);
                if ($get_goods['is_lock'] == 2) {
                    $get_sale = $saledb->where('goods_sku', $get_goods['goods_sku'])->order('sale_price_id', 'desc')->find();
                    // 同步商品表库存
                    $temp = array();
                    $data_goods = array();
                    $data_goods['view_stock'] = $view_stock_arr;
                    $data_goods['audit_goods'] = $view_stock_arr;
                    // 报价真实库存
                    if (isset($this->post['zhenshi_arr'])) {
                        $data_goods['zhenshi'] = $this->post['zhenshi_arr'][$key];
                        $data_goods['down_time'] = time() + $this->post['zhouqi_arr'][$key] * 86400;
                        //if ($get_goods['check_area'] == 1) {
                        $data_goods['diqu'] = $this->post['diqu_arr'][$key];
                        if ($this->post['shengfen_arr'][$key]) {
                            $data_goods['shengfen'] = implode(',', $this->post['shengfen_arr'][$key]);
                        } else {
                            $data_goods['shengfen'] = '';
                        }
                        $temp['zhenshi'] = $data_goods['zhenshi'];
                        $temp['diqu'] = $data_goods['diqu'];
                        $temp['shengfen'] = $data_goods['shengfen'];
                        //}
                    }
                    $get_goods->save($data_goods);
                    $temp ['goods_id'] = $this->post ['goods_id_arr'] [$key];
                    $temp ['baojia'] = $this->post ['api_price_arr'] [$key];
                    $temp ['kucun'] = $view_stock_arr;
                    $temp ['apply_member_id'] = MEMBER_ID;
                    $temp['audit_state'] = $audit_flag;
                    $temp['goods_type'] = strstr($this->post ['goods_sku_arr'] [$key], 'SKU') ? '自选库' : '重点库';
                    $temp['goods_sku'] = $this->post ['goods_sku_arr'] [$key];
                    $temp['goods_shuzi'] = $get_goods['jun_id'];
                    $temp['goods_name'] = $this->post['goods_name_arr'][$key];
                    $temp['cankao'] = $get_sale['sale_price'];
                    $temp['caigoujia'] = $get_sale['caigoujia'];
                    $temp['beizhu1'] = $get_sale['chengbenjia'];
                    $temp['beizhu2'] = $get_sale['beizhu'];
                    $temp['chengben'] = $this->post['chengbenjia_arr'][$key] ?: $temp['baojia'];
                    $temp['lilv'] = ($temp ['baojia'] - $temp['chengben']) / $temp['baojia'];
                    $temp['lilv2'] = ($temp ['cankao'] - $temp['baojia']) / $temp['cankao'];
                    $temp['beizhu'] = $this->post['beizhu_arr'][$key];
                    $temp['zhouqi'] = time() + $this->post['zhouqi_arr'][$key] * 86400;
                    if ($this->post['zhouqi_arr'][$key] == 365) {
                        $temp['zhouqi'] = strtotime('2024-01-01');
                    }
                    // 15%直接审核通过 后面最佳参考价大于50000的要审核
                    if ((floatval($temp['cankao']) < 50000) && ((floatval(abs($temp['lilv2'])) <= 0.25) || (floatval(abs($temp['lilv2'])) > 0.25 && floatval(abs($temp['lilv2'])) <= 0.35 && floatval(abs($temp['lilv'])) >= 0.1 && floatval(abs($temp['lilv'])) <= 0.5))) {
                        // if (floatval(abs($temp['lilv2'])) <= 0.15) {
                        $temp['audit_state'] = 1;
                        $temp['audit_member_id'] = MEMBER_ID;
                        $temp['audit_time'] = time();
                        //  $temp['beizhu'] = $temp['beizhu'] . '__低于15%自动审核';
                        // 推送军采
                        $junapi = new Api();
                        if ($temp['goods_type'] == '重点库') {
                            $post_jun['priceList'] = array();
                            $price_list_arr['sku'] = $temp['goods_sku'];
                            $price_list_arr['stock'] = $temp['kucun'];
                            $price_list_arr['price'] = $temp['baojia'];
                            $price_list_arr['linkurl'] = 'http://tailongjipc.dixintong.com/goods_detail.html?goods_sku=' . $this->post ['goods_id_arr'] [$key];
                            $price_list_arr['eccode'] = $this->post ['goods_id_arr'] [$key];
                            $price_list_arr['linkprice'] = $temp['baojia'];
                            array_push($post_jun['priceList'], $price_list_arr);
                            $push_result = $junapi->ajaxCountPrice($post_jun);
                            // 写商品日志
                            $temp_price_log = [];
                            $temp_price_log['goods_sku'] = $get_goods['goods_sku'];
                            $temp_price_log['date'] = date('Y-m-d H:i:s');
                            $temp_price_log['types'] = '供应商报价';
                            $temp_price_params = [];
                            $temp_price_params['用户'] = $get_supplier;
                            $temp_price_params['参考价'] = $get_sale['sale_price'];
                            $temp_price_params['成本'] = $get_sale['caigoujia'];
                            $temp_price_params['报价'] = $this->post ['api_price_arr'] [$key];
                            $temp_price_params['库存'] = $view_stock_arr;
                            $temp_price_params['真实库存'] = $this->post['zhenshi_arr'][$key] ?? '';
                            $temp_price_params['最低价'] = $get_sale['zuidijia'];
                            $temp_price_params['结果'] = $push_result['priceList'][0]['reason'];
                            $temp_price_log['params'] = json_encode($temp_price_params, JSON_UNESCAPED_UNICODE);
                            array_push($goods_price_arr, $temp_price_log);
                            // 商品日志结束
                        } else {
                            $data = array();
                            $temp1 ['sku'] = $temp['goods_sku'];
                            $temp1 ['updateType'] = 6;
                            array_push($data, $temp1);
                            $junapi->ajaxproductupdateinfo($data);
                        }
                        // 同步商品价格
                        $salepricedb = new SalePricedb();
                        $get_sale = $salepricedb->where('site_id', SITE_ID)->where('goods_sku', $temp['goods_sku'])->find();
                        $get_sale->save(['api_price' => $temp['baojia'], 'view_stock' => $temp['kucun']]);

                        // 同步分系统
                        $uGoodsdb = new UGoodsdb();
                        $uGoodsdb->chkGoods($temp['goods_id']);

                    }

                    array_push($param, $temp);
                }

            }
            // halt($param);
            if (count($param)) {
                $baojiadb->saveAll($param);
            }
            // 批量写商品日志
            if (count($goods_price_arr)) {
                $goodsPriceLogdb = new GoodsPriceLogdb();
                $goodsPriceLogdb->saveAll($goods_price_arr);
            }
            $this->layuiReturn('提交成功', 0, '提交成功', 1);

        }
    }

    public function exportCgGoods()
    {
        set_time_limit(0);
        $count = $this->db->ajaxCount();
        $this->db->param ['page'] = 1;
        $this->db->param ['limit'] = $count;
        $this->db->param ['pre_info'] = 'jun';
        $data = $this->db->ajaxList();

        vendor("PHPExcel.PHPExcel");
        $phpExcel = new \PHPExcel ();
        ob_end_clean();
        $excel_name = '产品' . date('Ymdhi') . rand(1000, 9999) . '.xls';
        $obj_write = new \PHPExcel_Writer_Excel5 ($phpExcel);
        $obj_act_sheet = $phpExcel->getActiveSheet();
        $i = 1;
        $header_data = array(
            '一级分类',
            '二级分类',
            '三级分类',
            '品牌名称',
            '商品名称',
            '商品编号',
            '参考价（元）',
            '报价（元）',
            '库存',
            '图片'
        );
        $this->setExcelHeader($obj_act_sheet, $phpExcel, $header_data);
        $excel_data = array();
        foreach ($data as $key => $val) {
            $api_price = 0;
            if (isset ($this->post ['api_price_arr'])) {
                foreach ($this->post ['goods_id_arr'] as $k => $v) {
                    if ($val ['goods_id'] == $v) {
                        $api_price = $this->post ['api_price_arr'] [$k];
                        $view_stock = $this->post ['view_stock_arr'] [$k];
                    }
                }
            }
            $temp = array(
                $val ['category_name1'],
                $val ['category_name2'],
                $val ['category_name'],
                $val ['jun_brand_name'],
                $val ['goods_name'],
                $val ['goods_sku'],
                $val ['sale_price'],
                $api_price,
                $view_stock,
                $val ['goods_picture'] ['save_path']
            );
            array_push($excel_data, $temp);
        }
        $vAlign = new \PHPExcel_Style_Alignment ();
        $this->setExcelBody($obj_act_sheet, $phpExcel, $excel_data, count($header_data), $vAlign::VERTICAL_CENTER);

        $obj_write->save('./uploads/Excel/' . $excel_name);
        $all_path = $excel_name;
        $this->layuiReturn(url('Order/downExcel', array(
            'excel_name' => $all_path
        )), 1, '导出成功', 1);
    }

    public function exportGoods()
    {
        set_time_limit(0);
        $count = $this->db->ajaxCount();
        $this->db->param ['page'] = 1;
        $this->db->param ['limit'] = $count;
        $data = $this->db->ajaxList();
        vendor("PHPExcel.PHPExcel");
        $phpExcel = new \PHPExcel ();
        ob_end_clean();
        $excel_name = '产品' . date('Ymdhi') . '.' . rand(1000, 9999) . '.xls';
        $obj_write = new \PHPExcel_Writer_Excel5 ($phpExcel);
        $obj_act_sheet = $phpExcel->getActiveSheet();
        $i = 1;
        $header_data = array();
        foreach ($this->cols as $key => $val) {
            if (isset ($val ['title']) && isset ($val ['field']) && $key != 0 && $key != count($this->cols)) {
                array_push($header_data, $val ['title']);
            }
        }
        $this->setExcelHeader($obj_act_sheet, $phpExcel, $header_data);
        $excel_data = array();
        foreach ($data as $key => $val) {
            $temp = array();
            foreach ($this->cols as $k => $v) {
                if (isset ($v ['title']) && isset ($v ['field']) && $k != 0 && $k != count($this->cols)) {
                    switch ($v ['field']) {
                        case 'goods_picture' :
                            $temp [] = $val ['goods_picture'] ['save_path'];
                            break;
                        case 'audit_state' :
                            if ($val ['audit_state'] == 1) {
                                $temp [] = '已审核';
                            } elseif ($val ['audit_state'] == 0) {
                                $temp [] = '等待审核';
                            } else {
                                $temp [] = '驳回审核';
                            }
                        default :
                            if ($val [$v ['field']] === TRUE) {
                                $temp [] = '是';
                            } elseif ($val [$v ['field']] === FALSE) {
                                $temp [] = '否';
                            } else {
                                $temp [] = $val [$v ['field']];
                            }
                            break;
                    }
                }
            }
            array_push($excel_data, $temp);
        }
        $vAlign = new \PHPExcel_Style_Alignment ();
        $this->setExcelBody($obj_act_sheet, $phpExcel, $excel_data, count($header_data), $vAlign::VERTICAL_CENTER);

        $obj_write->save('./uploads/Excel/' . $excel_name);
        $all_path = $excel_name;
        $this->layuiReturn(url('Order/downExcel', array(
            'excel_name' => $all_path
        )), 1, '导出成功', 1);
    }

    public function downExcel($excel_name)
    {
        $path_excel_name = $_SERVER ['REQUEST_SCHEME'] . '://' . $_SERVER ['HTTP_HOST'] . '/uploads/Excel/' . $excel_name;
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-execl");
        header("Content-Type:application/octet-stream");
        header("Content-Type:application/download");
        header('Content-Disposition:attachment;filename=' . $excel_name . '');
        header("Content-Transfer-Encoding:binary");
        readfile($path_excel_name);
    }

    public function baojia()
    {
        return $this->fetch();
    }

    protected function setExcelHeader($obj_act_sheet, $phpExcel, $data)
    {
        $start = 65;
        for ($i = 0; $i < count($data); $i++) {
            if ($i >= 26) {
                $cell_value = chr(65) . chr($start + ($i - 26)) . '1';
            } else {
                $cell_value = chr($start + $i) . '1';
            }
            $obj_act_sheet->setCellValue($cell_value, $data [$i]);
            $phpExcel->getActiveSheet()->getColumnDimension(chr($start + $i))->setWidth(20);
        }
    }

    protected function setExcelBody($obj_act_sheet, $phpExcel, $data, $count, $valign)
    {
        $start = 65;
        for ($i = 0; $i < $count; $i++) {
            if ($i >= 26) {
                $cell_value = chr(65) . chr($start + ($i - 26));
            } else {
                $cell_value = chr($start + $i);
            }
            $j = 2;
            foreach ($data as $key => $val) {
                $obj_act_sheet->setCellValue($cell_value . $j, $val [$i]);
                $phpExcel->getActiveSheet()->getStyle($cell_value . $j)->getAlignment()->setVertical($valign);
                $j++;
            }
        }
    }

    /**
     * Title("校验今日报价商品")
     */
    public function chkTodayBaojia()
    {
        $data = Db::name('goods_price_log')
            //->fetchSql(true)
            ->whereIn('goods_sku', $this->post['goods_sku_arr'])
            ->whereIn('types', ['供应商报价', '军采统一报价', '产品详情报价', '同步军网报价', '报价审核', '自动推送下架'])
            ->whereTime('date', 'today')
            ->whereLike('params','%"结果":"入库成功"%')
            ->group('goods_sku')
            ->field('count(*) count,goods_sku')
            ->select();
        $this->layuiReturn($data);
    }
}